import parameterized
import requests
import unittest
from ..api.login_api import LoginAPI
class TestLoginAPI(unittest.TestCase):

    # 前置处理
    def setUp(self):
        self.login_api = LoginAPI()
        self.session = requests.Session()

    def tearDown(self):
        if self.session:
            self.session.close()

    @parameterized.expand(build_data)
    def test01_login(self, username, password, verify_code, status_code, content_type, status, msg):
        # 调用验证码接口
        response = self.login_api.login.get_verify_code(self.session)

        # 断言
        self.assertEqual(status_code,response.status_code)
        self.assertIn(content_type,response.headers.get('content-type'))

        # 调用登录接口
        response = self.login_api.login(self.session, username, password, verify_code)
        print(response.json())
        self.assertEqual(status_code, response.status_code)
        self.assertEqual(status,response.json().get('status'))
        self.assertIn(msg,response.json().get('message'))